package com.haixee.parkdemo.auth.utils;

import com.haixee.parkdemo.common.context.WebContextHolder;
import com.haixee.parkdemo.common.exception.BusinessException;
import com.haixee.parkdemo.common.response.CommonResEnum;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TenantUtil {

    public static Integer check(Integer tenantId) {

        Integer userTen = WebContextHolder.getAuth().getTenantId();
        if (tenantId == null) {

            if (userTen.equals(0)) {
                return tenantId;
            }
            return tenantId;
        } else {
            if (userTen.equals(0) || userTen.equals(tenantId)) {
                return tenantId;
            } else {
                log.error("[无法使用该园区数据], uid:[{}], curTenant:[{}], useTenant:[{}]", WebContextHolder.getUid(), userTen, tenantId);
                throw new BusinessException(CommonResEnum.BAD_REQUEST);
            }
        }

    }
}
